# -*- encoding=utf-8 -*-

from froModuleDrivers.mCarDriver import MCarDriver  # 引用小车驱动模块
from froModuleDrivers.nioManager import NioManager  # 引用驱动管理模块
from froModuleDrivers import LOGGER
import time

mycar = MCarDriver("192.168.3.196", 4001)  # 实例化网关驱动
manager = NioManager(mycar)  # 实例化驱动管理模块，并把网关驱动加入管理
manager.run()  # 系统运行
# LOGGER.set_lvl("debug")
# LOGGER.create_logger("debug.log","debug")
mycar.setLanternMode(0xFF)
a = [
    0xff0000, 0xff00, 0xff, 0xffffff, 0xff0000, 0xff00, 0xff, 0xffffff,
    0xff0000, 0xff00, 0xff, 0xffffff, 0xff0000, 0xff00, 0xff, 0xffffff
]
mycar.setLantern(a)

# mycar.setCarSingleWheelControlMode()
# mycar.ctrlCarByWheel(-25,-25,25,25)
# mycar.ctrlCarByWheel(25,25,25,25)
# time.sleep(1)
# mycar.ctrlCarByWheel(-25,25,-25,25)
# time.sleep(1)
# mycar.ctrlCarByWheel(0,0,0,0)
# mycar.inPark1()
# mycar.inPark2()
# mycar.outPark()

# mycar.inCharge1()
# mycar.inCharge2()
# mycar.outCharge()
# mycar.setTurnLeftCard([0x0c01])
# mycar.setTurnRightCard([0x0B01,0x0B02,0x0B03])
mycar.setTurnCard([0x0001], [0x0B01, 0x0B02, 0x0B03])

# print(mycar.getTurnLeftCard())
# print(mycar.getTurnRightCard())
# mycar.parkPoint(0x0C01)
# mycar.setCarExpandPWMSingle()
# mycar.setCarExpandPWM()

# print(mycar.getInfrStatus())
# while True:
#     LOGGER.logger.debug(mycar.refreshStatus())
# mycar.playCarSpeechInside(1)
mycar.playCarSpeech("你好啊")
# print(mycar.getDistance(),"cm")
print(mycar.refreshStatus())
# mycar.setCarSpeed(35)
# mycar.startCar()
# print(mycar.getCarStatus())
# print(mycar.getFirmwareVersion())
# time.sleep(1)
# mycar.setCarAutoMode()
# time.sleep(1)
# mycar.startCar()
# time.sleep(1)
# for i in range(10):
#     mycar.setCarSpeed(i*5)
#     time.sleep(1)

# time.sleep(5)
# mycar.stopCar()
time.sleep(5)

# mycar.setCarAutoMode()
# mycar.setCarManualMode()
# time.sleep(5)
manager.shutdownGracefully()  # 等待指令执行完毕后系统退出
